<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>编译作用域</title>
</head>
<body>
<div id="app">
    <cpn></cpn>
</div>

<template id="cpn">
    <h1>这是自定义组件</h1>
    <button v-show="status">提交</button>
    <div>{{ info }}</div>
</template>

<script type="module">
    import {createApp, ref, defineComponent} from "../../../js/vue.esm-browser.js";

    let component = defineComponent(
        {
            template: "#cpn",
            setup() {
                // 组件使用自身的变量
                // 组件之间的 同名 变量 也不会起作用
                let status = ref(false)
                let info = ref("Hello, Vue!")
                return {
                    status, info,
                }
            }

        }
    );

    let app = createApp(
        {
            setup() {
                // 非组件内部定义的变量不能在组件中使用
                let status = ref(false)

                let info = ref("Hello, Vue!")
                return {
                    status, info,
                }
            }
        }
    );

    app.component("cpn", component)

    app.mount("#app")
</script>
</body>
</html>